﻿package net.wangit.dev.settings;

import net.wangit.Path;
import net.wangit.Row;
import net.wangit.context.ActionContext;
import net.wangit.support.ElementWriter;
import net.wangit.util.FileUtil;
import net.wangit.view.element.ElementComponent;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


public class DomainsElementWriter implements ElementWriter {

	private static final Log log = LogFactory
			.getLog(net.wangit.dev.settings.DomainsElementWriter.class);

	public DomainsElementWriter() {
	}

	public void write(ActionContext ac, StringBuffer html, ElementComponent ec,
			Row row) {
		try {
			String domains[] = FileUtil
					.listDirectorys(Path.getDomainRootPath());
			for (int i = 0; i < domains.length; i++) {
				String domain = domains[i];
				String datasourcePath = (new StringBuilder(String.valueOf(Path
						.getDomainPath(domain)))).append("datasource.xml")
						.toString();
				if (FileUtil.exists(datasourcePath))
					html.append(domain).append("<br>");
			}

		} catch (Exception e) {
			log.error("read domains failed!", e);
		}
	}

}
